<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/facicon.ico?v=5.1.4" color="#222">





  <meta name="keywords" content="HTML,CSS3,CSS,">





  <link rel="alternate" href="/atom.xml" title="Key" type="application/atom+xml">






<meta name="description" content="弹性布局(fiexible box)模块旨在提供一个更加有效的方式来布置,对齐和分布在容器之间的各项内容,即使他们的大小是未知或者动态变化的.弹性布局的主要思想是让容器有能力来改变项目的宽度和高度,以填满可用空间(主要是为了容纳所有类型的显示设备和屏幕尺寸)的能力.最重要的是弹性盒子布局与方向无关,相对于常规的布局(块是垂直和内联为基础的),很显然,这些工作以及网页设计缺乏灵活性,无法支持大型和复">
<meta name="keywords" content="HTML,CSS3,CSS">
<meta property="og:type" content="article">
<meta property="og:title" content="伸缩盒子(flex)">
<meta property="og:url" content="https://blog.qipo.net/2017/08/31/fiex/index.html">
<meta property="og:site_name" content="Key">
<meta property="og:description" content="弹性布局(fiexible box)模块旨在提供一个更加有效的方式来布置,对齐和分布在容器之间的各项内容,即使他们的大小是未知或者动态变化的.弹性布局的主要思想是让容器有能力来改变项目的宽度和高度,以填满可用空间(主要是为了容纳所有类型的显示设备和屏幕尺寸)的能力.最重要的是弹性盒子布局与方向无关,相对于常规的布局(块是垂直和内联为基础的),很显然,这些工作以及网页设计缺乏灵活性,无法支持大型和复">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://assets.qipo.net/flex.jpg">
<meta property="og:image" content="http://assets.qipo.net/flex2.png">
<meta property="og:updated_time" content="2020-06-04T08:30:16.904Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="伸缩盒子(flex)">
<meta name="twitter:description" content="弹性布局(fiexible box)模块旨在提供一个更加有效的方式来布置,对齐和分布在容器之间的各项内容,即使他们的大小是未知或者动态变化的.弹性布局的主要思想是让容器有能力来改变项目的宽度和高度,以填满可用空间(主要是为了容纳所有类型的显示设备和屏幕尺寸)的能力.最重要的是弹性盒子布局与方向无关,相对于常规的布局(块是垂直和内联为基础的),很显然,这些工作以及网页设计缺乏灵活性,无法支持大型和复">
<meta name="twitter:image" content="http://assets.qipo.net/flex.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://blog.qipo.net/2017/08/31/fiex/">





  <title>伸缩盒子(flex) | Key</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Key</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog.qipo.net/2017/08/31/fiex/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Key">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Key">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">伸缩盒子(flex)</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-31T08:16:54+08:00">
                2017-08-31
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CSS/" itemprop="url" rel="index">
                    <span itemprop="name">CSS</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3.2k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  11
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>弹性布局(fiexible box)模块旨在提供一个更加有效的方式来布置,对齐和分布在容器之间的各项内容,即使他们的大小是未知或者动态变化的.<br>弹性布局的主要思想是让容器有能力来改变项目的宽度和高度,以填满可用空间(主要是为了容纳所有类型的显示设备和屏幕尺寸)的能力.<br>最重要的是弹性盒子布局与方向无关,相对于常规的布局(块是垂直和内联为基础的),很显然,这些工作以及网页设计缺乏灵活性,无法支持大型和复杂的应用程序(特别是当他涉及到改变方向,缩放,拉伸和收缩等).</p>
<p><img src="http://assets.qipo.net/flex.jpg" alt></p>
<blockquote>
<p>要想设置一个弹性盒子,必须在其父元素设置<code>display:flex</code>!!!设置父元素之后,所有子元素会在一行上,但是他们并没有脱离标准流.</p>
</blockquote>
<h2 id="flex-伸缩盒子-常用属性"><a href="#flex-伸缩盒子-常用属性" class="headerlink" title="flex(伸缩盒子)常用属性"></a>flex(伸缩盒子)常用属性</h2><h3 id="flex-grow"><a href="#flex-grow" class="headerlink" title="flex-grow: "></a>flex-grow: <number></number></h3><ul>
<li><p>取值:<code>&lt;number&gt;</code>用数值来定义扩展比率.不允许为负值.</p>
</li>
<li><p>说明:设置或检索弹性盒子的扩展比率.根据弹性盒子元素所设置的扩展因子作为比率来分配剩余空间.</p>
</li>
</ul>
<p>演示:</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>flex<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span> <span class="attr">media</span>=<span class="string">"screen"</span>&gt;</span><span class="undefined"></span></span><br><span class="line"><span class="undefined">      *&#123;</span></span><br><span class="line"><span class="undefined">        border: 0px;</span></span><br><span class="line"><span class="undefined">        padding: 0px;</span></span><br><span class="line"><span class="undefined">      &#125;</span></span><br><span class="line"><span class="css">      <span class="selector-class">.one</span>&#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">width</span><span class="selector-pseudo">:1000px</span>;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">height</span><span class="selector-pseudo">:500px</span>;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">border</span><span class="selector-pseudo">:solid</span> 1<span class="selector-tag">px</span> <span class="selector-tag">red</span>;</span></span><br><span class="line"><span class="undefined">        display: flex;   </span></span><br><span class="line"><span class="css">        <span class="comment">/* 设置伸缩盒子,必须在父元素中设置这个属性,设置以后,子元素会在一行上,但是并没有脱离标准流. */</span></span></span><br><span class="line"><span class="undefined">      &#125;</span></span><br><span class="line"><span class="css">      <span class="selector-class">.one</span> &gt; <span class="selector-tag">div</span>&#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">width</span><span class="selector-pseudo">:300px</span>;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">height</span><span class="selector-pseudo">:200px</span>;</span></span><br><span class="line"><span class="undefined">        background: lightblue;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">flex-grow</span><span class="selector-pseudo">:1</span>;   </span></span><br><span class="line"><span class="css">        <span class="comment">/* 这是设置扩展比例,当然也是可以每个子元素设置不同的比例. */</span></span></span><br><span class="line"><span class="undefined">      &#125;</span></span><br><span class="line"><span class="undefined">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one"</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one-1"</span>&gt;</span></span><br><span class="line">        1</span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one-2"</span>&gt;</span></span><br><span class="line">        2</span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"one-3"</span>&gt;</span></span><br><span class="line">        3</span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>显示如下:</p>
<p><img src="http://assets.qipo.net/flex2.png" alt></p>
<p>可以看到子元素占据了全部的空间,这就是<code>flex-grow:1;</code>的功劳.每个子元素的宽是300px,父盒子的宽是1000px,应该还剩下100px,这个参数就是来分配这剩下的100px的归属的,当子元素的这个参数全部设置为1时,所有子元素的这个参数加起来为3,剩下的100px就会被分割成3份,每个子元素分得一份,每个盒子的宽度就是200px+(100px/3).</p>
<h3 id="flex-shrink："><a href="#flex-shrink：" class="headerlink" title="flex-shrink："></a>flex-shrink：<number></number></h3><ul>
<li>取值:<number>:用数值来定义收缩比率.不允许负值.   </number></li>
<li>说明:设置或者检索弹性盒的收缩比率.根据弹性盒子元素所设置收缩因子作为比率来收缩空间.</li>
</ul>
<p>演示:</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&lt;<span class="selector-tag">ul</span> class=<span class="string">"flex"</span>&gt;</span><br><span class="line">    &lt;li&gt;a&lt;/li&gt;</span><br><span class="line">    &lt;li&gt;b&lt;/li&gt;</span><br><span class="line">    &lt;li&gt;c&lt;/li&gt;</span><br><span class="line">&lt;/ul&gt;</span><br><span class="line"></span><br><span class="line">.<span class="attribute">flex</span>&#123;display:flex;<span class="attribute">width</span>:<span class="number">400px</span>;<span class="attribute">margin</span>:<span class="number">0</span>;<span class="attribute">padding</span>:<span class="number">0</span>;<span class="attribute">list-style</span>:none;&#125;</span><br><span class="line"><span class="selector-class">.flex</span> li&#123;<span class="attribute">width</span>:<span class="number">200px</span>;&#125;</span><br><span class="line"><span class="selector-class">.flex</span> <span class="selector-tag">li</span>:nth-child(<span class="number">3</span>)&#123;<span class="attribute">flex-shrink</span>:<span class="number">3</span>;&#125;</span><br></pre></td></tr></table></figure>
<p>a,b,c 将按照1:1:3的比率来收缩空间.<code>fiex-shrink</code>的默认值为1,如果没有显示定义该属性,将会自动按照默认值1在所有因子相加之后计算比率来进行空间收缩.本例中c显式的定义了<code>flex-shrink</code>，a,b没有显式定义，但将根据默认值1来计算，可以看到总共将剩余空间分成了5份，其中a占1份，b占1份，c占3分，即1:1:3<br>我们可以看到父容器定义为400px，子项被定义为200px，相加之后即为600px，超出父容器200px。那么这么超出的200px需要被a,b,c消化<br>通过收缩因子，所以加权综合可得200<em>1+200</em>1+200<em>3=1000px；<br>于是我们可以计算a,b,c将被移除的溢出量是多少：<br>a被移除溢出量：(200</em>1/1000)<em>200，即约等于40px<br>b被移除溢出量：(200</em>1/1000)<em>200，即约等于40px<br>c被移除溢出量：(200</em>3/1000)*200，即约等于120px<br>最后a,b,c的实际宽度分别为：200-40=160px, 200-40=160px, 200-120=80px   </p>
<h3 id="flex-direction-row-row-reverse-column-column-reverse"><a href="#flex-direction-row-row-reverse-column-column-reverse" class="headerlink" title="flex-direction: row | row-reverse | column | column-reverse"></a>flex-direction: row | row-reverse | column | column-reverse</h3><p>取值:</p>
<ul>
<li>row：主轴与行内轴方向作为默认的书写模式。即横向从左到右排列（左对齐）。(默认值)</li>
<li>row-reverse：对齐方式与row相反。</li>
<li>column：主轴与块轴方向作为默认的书写模式。即纵向从上往下排列（顶对齐）。</li>
<li>column-reverse：对齐方式与column相反。</li>
</ul>
<p>说明: 该属性通过定义flex容器的主轴方向来决定felx子项在flex容器中的位置。这将决定flex需要如何进行排列.主轴方向默认为x轴,即横轴.</p>
<h3 id="flex-wrap：nowrap-wrap-wrap-reverse"><a href="#flex-wrap：nowrap-wrap-wrap-reverse" class="headerlink" title="flex-wrap：nowrap | wrap | wrap-reverse"></a>flex-wrap：nowrap | wrap | wrap-reverse</h3><p>取值：</p>
<ul>
<li>nowrap：flex容器为单行。该情况下flex子项可能会溢出容器</li>
<li>wrap：flex容器为多行。该情况下flex子项溢出的部分会被放置到新行，子项内部会发生断行</li>
<li>wrap-reverse：反转 wrap 排列。</li>
</ul>
<p>说明: 该属性控制flex容器是单行或者多行，同时横轴的方向决定了新行堆叠的方向。</p>
<h3 id="align-content：flex-start-flex-end-center-space-between-space-around-stretch"><a href="#align-content：flex-start-flex-end-center-space-between-space-around-stretch" class="headerlink" title="align-content：flex-start | flex-end | center | space-between | space-around | stretch"></a>align-content：flex-start | flex-end | center | space-between | space-around | stretch</h3><p>取值：</p>
<ul>
<li>flex-start：各行向弹性盒容器的起始位置堆叠。弹性盒容器中第一行的侧轴起始边界紧靠住该弹性盒容器的侧轴起始边界，之后的每一行都紧靠住前面一行。</li>
<li>flex-end：各行向弹性盒容器的结束位置堆叠。弹性盒容器中最后一行的侧轴起结束界紧靠住该弹性盒容器的侧轴结束边界，之后的每一行都紧靠住前面一行。</li>
<li>center：各行向弹性盒容器的中间位置堆叠。各行两两紧靠住同时在弹性盒容器中居中对齐，保持弹性盒容器的侧轴起始内容边界和第一行之间的距离与该容器的侧轴结束内容边界与第最后一行之间的距离相等。（如果剩下的空间是负数，则各行会向两个方向溢出的相等距离。）</li>
<li>space-between：各行在弹性盒容器中平均分布。如果剩余的空间是负数或弹性盒容器中只有一行，该值等效于’flex-start’。在其它情况下，第一行的侧轴起始边界紧靠住弹性盒容器的侧轴起始内容边界，最后一行的侧轴结束边界紧靠住弹性盒容器的侧轴结束内容边界，剩余的行则按一定方式在弹性盒窗口中排列，以保持两两之间的空间相等。</li>
<li>space-around：各行在弹性盒容器中平均分布，两端保留子元素与子元素之间间距大小的一半。如果剩余的空间是负数或弹性盒容器中只有一行，该值等效于’center’。在其它情况下，各行会按一定方式在弹性盒容器中排列，以保持两两之间的空间相等，同时第一行前面及最后一行后面的空间是其他空间的一半。</li>
<li>stretch：各行将会伸展以占用剩余的空间。如果剩余的空间是负数，该值等效于’flex-start’。在其它情况下，剩余空间被所有行平分，以扩大它们的侧轴尺寸。</li>
</ul>
<p>说明: 当伸缩容器的侧轴还有多余空间时，本属性可以用来调准「伸缩行」在伸缩容器里的对齐方式，这与调准伸缩项目在主轴上对齐方式的 &lt;’ justify-content ‘&gt; 属性类似。请注意本属性在只有一行的伸缩容器上没有效果。</p>
<h3 id="align-items：flex-start-flex-end-center-baseline-stretch"><a href="#align-items：flex-start-flex-end-center-baseline-stretch" class="headerlink" title="align-items：flex-start | flex-end | center | baseline | stretch"></a>align-items：flex-start | flex-end | center | baseline | stretch</h3><p>取值：</p>
<ul>
<li>flex-start：弹性盒子元素的侧轴（纵轴）起始位置的边界紧靠住该行的侧轴起始边界。</li>
<li>flex-end：弹性盒子元素的侧轴（纵轴）起始位置的边界紧靠住该行的侧轴结束边界。</li>
<li>center：弹性盒子元素在该行的侧轴（纵轴）上居中放置。（如果该行的尺寸小于弹性盒子元素的尺寸，则会向两个方向溢出相同的长度）。</li>
<li>baseline：如弹性盒子元素的行内轴与侧轴为同一条，则该值与’flex-start’等效。其它情况下，该值将参与基线对齐。</li>
<li>stretch：如果指定侧轴大小的属性值为’auto’，则其值会使项目的边距盒的尺寸尽可能接近所在行的尺寸，但同时会遵照’min/max-width/height’属性的限制。</li>
</ul>
<p>说明: 定义flex子项在flex容器的当前行的侧轴（纵轴）方向上的对齐方式。</p>
<h3 id="align-self：auto-flex-start-flex-end-center-baseline-stretch"><a href="#align-self：auto-flex-start-flex-end-center-baseline-stretch" class="headerlink" title="align-self：auto | flex-start | flex-end | center | baseline | stretch"></a>align-self：auto | flex-start | flex-end | center | baseline | stretch</h3><p>取值：</p>
<ul>
<li>auto：如果’align-self’的值为’auto’，则其计算值为元素的父元素的’align-items’值，如果其没有父元素，则计算值为’stretch’。</li>
<li>flex-start：弹性盒子元素的侧轴（纵轴）起始位置的边界紧靠住该行的侧轴起始边界。</li>
<li>flex-end：弹性盒子元素的侧轴（纵轴）起始位置的边界紧靠住该行的侧轴结束边界。</li>
<li>center：弹性盒子元素在该行的侧轴（纵轴）上居中放置。（如果该行的尺寸小于弹性盒子元素的尺寸，则会向两个方向溢出相同的长度）。</li>
<li>baseline：如弹性盒子元素的行内轴与侧轴为同一条，则该值与’flex-start’等效。其它情况下，该值将参与基线对齐。</li>
<li>stretch：如果指定侧轴大小的属性值为’auto’，则其值会使项目的边距盒的尺寸尽可能接近所在行的尺寸，但同时会遵照’min/max-width/height’属性的限制。</li>
</ul>
<p>说明: 定义flex子项单独在侧轴（纵轴）方向上的对齐方式。</p>
<h3 id="justify-content：flex-start-flex-end-center-space-between-space-around"><a href="#justify-content：flex-start-flex-end-center-space-between-space-around" class="headerlink" title="justify-content：flex-start | flex-end | center | space-between | space-around"></a>justify-content：flex-start | flex-end | center | space-between | space-around</h3><p>取值：</p>
<ul>
<li>flex-start：弹性盒子元素将向行起始位置对齐。该行的第一个子元素的主起始位置的边界将与该行的主起始位置的边界对齐，同时所有后续的伸缩盒项目与其前一个项目对齐。</li>
<li>flex-end：弹性盒子元素将向行结束位置对齐。该行的第一个子元素的主结束位置的边界将与该行的主结束位置的边界对齐，同时所有后续的伸缩盒项目与其前一个项目对齐。</li>
<li>center：弹性盒子元素将向行中间位置对齐。该行的子元素将相互对齐并在行中居中对齐，同时第一个元素与行的主起始位置的边距等同与最后一个元素与行的主结束位置的边距（如果剩余空间是负数，则保持两端相等长度的溢出）。</li>
<li>space-between：弹性盒子元素会平均地分布在行里。如果最左边的剩余空间是负数，或该行只有一个子元素，则该值等效于’flex-start’。在其它情况下，第一个元素的边界与行的主起始位置的边界对齐，同时最后一个元素的边界与行的主结束位置的边距对齐，而剩余的伸缩盒项目则平均分布，并确保两两之间的空白空间相等。</li>
<li>space-around：弹性盒子元素会平均地分布在行里，两端保留子元素与子元素之间间距大小的一半。如果最左边的剩余空间是负数，或该行只有一个伸缩盒项目，则该值等效于’center’。在其它情况下，伸缩盒项目则平均分布，并确保两两之间的空白空间相等，同时第一个元素前的空间以及最后一个元素后的空间为其他空白空间的一半。</li>
</ul>
<p>说明:设置或检索弹性盒子元素在主轴（横轴）方向上的对齐方式。<br>当弹性盒里一行上的所有子元素都不能伸缩或已经达到其最大值时，这一属性可协助对多余的空间进行分配。当元素溢出某行时，这一属性同样会在对齐上进行控制。</p>
<h3 id="order："><a href="#order：" class="headerlink" title="order："></a>order：<integer></integer></h3><p>取值：</p>
<ul>
<li><code>&lt;integer&gt;</code>：用整数值来定义排列顺序，数值小的排在前面。可以为负值。</li>
</ul>
<p>说明：设置或检索弹性盒模型对象的子元素出現的順序。order定义将会影响 &lt;’ position ‘&gt; 值为static元素的层叠级别，数值小的会被数值大的盖住。</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Key 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Key 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/HTML/" rel="tag"># HTML</a>
          
            <a href="/tags/CSS3/" rel="tag"># CSS3</a>
          
            <a href="/tags/CSS/" rel="tag"># CSS</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/08/29/ajax/" rel="next" title="Ajax">
                <i class="fa fa-chevron-left"></i> Ajax
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/31/media/" rel="prev" title="媒体查询">
                媒体查询 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Key">
            
              <p class="site-author-name" itemprop="name">Key</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">107</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">28</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/keyarea" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:wxkayle@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#flex-伸缩盒子-常用属性"><span class="nav-number">1.</span> <span class="nav-text">flex(伸缩盒子)常用属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#flex-grow"><span class="nav-number">1.1.</span> <span class="nav-text">flex-grow: </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#flex-shrink："><span class="nav-number">1.2.</span> <span class="nav-text">flex-shrink：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#flex-direction-row-row-reverse-column-column-reverse"><span class="nav-number">1.3.</span> <span class="nav-text">flex-direction: row | row-reverse | column | column-reverse</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#flex-wrap：nowrap-wrap-wrap-reverse"><span class="nav-number">1.4.</span> <span class="nav-text">flex-wrap：nowrap | wrap | wrap-reverse</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#align-content：flex-start-flex-end-center-space-between-space-around-stretch"><span class="nav-number">1.5.</span> <span class="nav-text">align-content：flex-start | flex-end | center | space-between | space-around | stretch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#align-items：flex-start-flex-end-center-baseline-stretch"><span class="nav-number">1.6.</span> <span class="nav-text">align-items：flex-start | flex-end | center | baseline | stretch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#align-self：auto-flex-start-flex-end-center-baseline-stretch"><span class="nav-number">1.7.</span> <span class="nav-text">align-self：auto | flex-start | flex-end | center | baseline | stretch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#justify-content：flex-start-flex-end-center-space-between-space-around"><span class="nav-number">1.8.</span> <span class="nav-text">justify-content：flex-start | flex-end | center | space-between | space-around</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#order："><span class="nav-number">1.9.</span> <span class="nav-text">order：</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-snowflake-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Key</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">190.8k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
